package java_thinking.unit_15._15_4;


import java_thinking.unit_15._15_3.Coffee;
import java_thinking.unit_15._15_3.Generator;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @Description :   利用生成器，可以很方便的填充一个Collection
 * @author: cww
 * @DateTime: 2019-04-02 22:12
 */

public class Generators {
    public static <T> Collection<T> fill(Collection<T> coll, Generator<T> gen, int n) {
        for (int i =0; i<n;i++){
            coll.add(gen.next());
        }
        return coll;
    }

    public static void main(String[] args) {
        Collection<Coffee> coffees = fill(new ArrayList<>(),new CoffeeGenerator(),4);
        for (Coffee coffee:coffees){
            System.out.println(coffee.toString());
        }
    }
}
